include(['com.unknown.Constants', 'com.unknown.Config'], 
function(){
	
	declare('com.unknown.KeyboardHandler');
	com.unknown.KeyboardHandler = function(gamewindow){
		this.gamewindow = gamewindow;
		this.input = new Vector2(0,0);
		
		this.onKeyDown = function(event){
			var speed = 15;
			var x = 0;
			var y = 0;
			if(event.keyCode == '38' || event.keyCode == '104' || event.keyCode == '87'){//UP
				y = -speed;
			}else if( event.keyCode == '40' || event.keyCode == '98' || event.keyCode == '83'){//Down
				y = speed;
			}else if( event.keyCode == '37' || event.keyCode == '100' || event.keyCode == '65'){//Left
				x = -speed
			}else if( event.keyCode == '39' || event.keyCode == '102' || event.keyCode == '68'){//Right
				x = speed;
			}else if( event.keyCode == '13' ){
				this.gamewindow.player.activate();
			}
			if( y != 0 ){
				this.input.y = y;
				this.gamewindow.player.inputChanged(this.input);
			}
			if( x != 0 ){
				this.input.x = x;
				this.gamewindow.player.inputChanged(this.input);
			}
			event.preventDefault();
			//Cancel the action to ensure we don't scroll
			return false;
		};
		this.onKeyUp = function(event){
			var x = -1;
			var y = -1;
			if(event.keyCode == '38' || event.keyCode == '104' || event.keyCode == '87'){//UP
				y = 0;
			}else if( event.keyCode == '40' || event.keyCode == '98' || event.keyCode == '83'){//Down
				y = 0;
			}else if( event.keyCode == '37' || event.keyCode == '100' || event.keyCode == '65'){//Left
				x = 0;
			}else if( event.keyCode == '39' || event.keyCode == '102' || event.keyCode == '68'){//Right
				x = 0;
			}
			if( y == 0 ){
				this.input.y = y;
				this.gamewindow.player.inputChanged(this.input);
			}
			if( x == 0 ){
				this.input.x = x;
				this.gamewindow.player.inputChanged(this.input);
			}
			event.preventDefault();
		};
		var scope = this;
		document.addEventListener('keydown', function(event){
			scope.onKeyDown(event);
		}, false);
		document.addEventListener('keyup', function(event){
			scope.onKeyUp(event);
		}, false);
	};
});